//
//  NBANewsAppDelegate.m
//  NBANews
//
//  Created by Liccon Chang on 11-1-6.
//  Copyright __MyCompanyName__ 2011. All rights reserved.
//

#import "NBANewsAppDelegate.h"
#import "FixturesController.h"
#import "RankingController.h"

@implementation NBANewsAppDelegate

@synthesize window;
@synthesize viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

	FixturesController* Fixtures = [[FixturesController alloc] init];
	Fixtures.title = @"赛程";
	
	RankingController* rank = [[RankingController alloc] init];
	rank.title = @"排名";
	
	UITabBarController* tabController = [[UITabBarController alloc] init];
	tabController.viewControllers = [NSArray arrayWithObjects:Fixtures, rank, nil];
	
	[Fixtures release];
	[rank release];
	
	viewController = [[UINavigationController alloc] initWithRootViewController:tabController];
	[tabController release];
	
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
	//[self getGamblingCompany];
	return YES;
}

-(void) getGamblingCompany{
	NSString *urlString = [Constant getAddress: EGamblingCompany];
	NSLog(@"*** from http request: %@",urlString);
	NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
	network = [[NetworkUtil alloc] initWithURL:url
								 withOperation:@"getGambling"
								  withDelegate:self 
								    onComplete:@selector(completeFetch:)
									   onError:@selector(errorFetch:)];
}

- (void)completeFetch:(NetworkUtil *)obj{
	NSMutableArray* company = [RegexParse RegexParseGamblingCompany:[network getResponse]];
	[network release];
	network = nil;
}

- (void)dealloc {
	if (network) {
		[network terminate];
		[network release];
	}
    [viewController release];
    [window release];
    [super dealloc];
}


@end
